/*
** 2247.c
** 
** Made by (seakage2h)
** Login   <seakage2h@seakage2h-ubuntu>
** 
** Started on  Sat Oct 11 16:22:41 2008 seakage2h
** Last update Sun May 12 01:17:25 2002 Speed Blue
*/
/*
 * EXPERIENCE: too much memory used....The same mistake again....
 *             too many mod/divide....High cpu consuming....
 *             OMG, th/nd/rd....111th, not 111st....so does 312, 413....
 */

/* #include "2247.h" */
#include <stdio.h>
#include <stdlib.h>

#define TEST_RANGE 2000000001
#define HUMBLE_RANGE 5843

int compare_ints( const void* a, const void* b ) {
     int* arg1 = (int*) a;
     int* arg2 = (int*) b;
     if( *arg1 < *arg2 ) return -1;
     else if( *arg1 == *arg2 ) return 0;
     else return 1;
}

int main()
{
/* char test[TEST_RANGE];	/\* deadly fatal error *\/ */
     int humble[HUMBLE_RANGE];
     int *humble_index = humble + 1;
     int i, i2, i3, i5, i7;
     unsigned long long int tmp57, tmp357, tmp2357, tmp;
     
     /* the largest power not exceeding 2000000000 */
     unsigned long long int pow2[31];
     unsigned long long int pow3[20];
     unsigned long long int pow5[14];
     unsigned long long int pow7[12];
     for(pow2[0] = pow3[0] = pow5[0] = pow7[0] = 1, i = 1; i < 12; i++){
	  pow2[i] = pow2[i-1] * 2;
	  pow3[i] = pow3[i-1] * 3;
	  pow5[i] = pow5[i-1] * 5;
	  pow7[i] = pow7[i-1] * 7;
     }
     while(i < 14){
	  pow2[i] = pow2[i-1] * 2;
	  pow3[i] = pow3[i-1] * 3;
	  pow5[i] = pow5[i-1] * 5;
	  i++;
     }
     while(i < 20){
	  pow2[i] = pow2[i-1] * 2;
	  pow3[i] = pow3[i-1] * 3;
	  i++;
     }
     while(i < 31){
	  pow2[i] = pow2[i-1] * 2;
	  i++;
     }

/*      memset(test, 0, TEST_RANGE); */

     for(i7 = 0; i7 < 12; i7++)
	  for(i5 = 0; i5 < 14; i5++)
	       if ((tmp57 = pow7[i7] * pow5[i5]) > TEST_RANGE) break;
	       else for(i3 = 0; i3 < 20; i3++)
			 if ((tmp357 = tmp57 * pow3[i3]) > TEST_RANGE) break;
			 else for(i2 = 0; i2 < 31; i2++)
				   if ((tmp2357 = tmp357 * pow2[i2]) >
				       TEST_RANGE)
					break;
				   else *humble_index++ = tmp2357;

/*      /\* look up the test numbers to extract humble numbers *\/ */
/*      for(i = 1, humble_index = humble + 1; i < TEST_RANGE; i++) */
/* 	  if (test[i]) *humble_index++ = i; */
     qsort(humble + 1, HUMBLE_RANGE - 1, sizeof(int), compare_ints);

     while(scanf("%d", &i)){
	  if (i == 0) break;
	  tmp = i % 100;
	  switch(tmp % 10){
	  case 1:
	       if (tmp == 11)
		    printf("The %dth humble number is %d.\n", i, humble[i]);
	       else
		    printf("The %dst humble number is %d.\n", i, humble[i]);
	       break;
	  case 2:
	       if (tmp == 12)
		    printf("The %dth humble number is %d.\n", i, humble[i]);
	       else
		    printf("The %dnd humble number is %d.\n", i, humble[i]);
	       break;
	  case 3:
	       if (tmp == 13)
		    printf("The %dth humble number is %d.\n", i, humble[i]);
	       else
		    printf("The %drd humble number is %d.\n", i, humble[i]);
	       break;
	  default:
	       printf("The %dth humble number is %d.\n", i, humble[i]);
	       break;
	  }
     }

     return 0;
}

/* int main() */
/* { */
/*      int humble[HUMBLE_RANGE]; */
/*      int *humble_index = humble + 1; */
/*      int i, i2, i3, i5, i7; */
/*      int tmp; */
     
/*      /\* the largest power not exceeding 2000000000 *\/ */
/*      unsigned int pow2[32]; */
/*      unsigned int pow3[20]; */
/*      unsigned int pow5[14]; */
/*      unsigned int pow7[12]; */
/*      for(pow2[0] = pow3[0] = pow5[0] = pow7[0] = 1, i = 1; i < 12; i++){ */
/* 	  pow2[i] = pow2[i-1] * 2; */
/* 	  pow3[i] = pow3[i-1] * 3; */
/* 	  pow5[i] = pow5[i-1] * 5; */
/* 	  pow7[i] = pow7[i-1] * 7; */
/*      } */
/*      while(i < 14){ */
/* 	  pow2[i] = pow2[i-1] * 2; */
/* 	  pow3[i] = pow3[i-1] * 3; */
/* 	  pow5[i] = pow5[i-1] * 5; */
/* 	  i++; */
/*      } */
/*      while(i < 20){ */
/* 	  pow2[i] = pow2[i-1] * 2; */
/* 	  pow3[i] = pow3[i-1] * 3; */
/* 	  i++; */
/*      } */
/*      while(i < 32){ */
/* 	  pow2[i] = pow2[i-1] * 2; */
/* 	  i++; */
/*      } */

/*      for(i = 1; i < TEST_RANGE; i++){ */
/* 	  tmp = i; */
/* 	  for(i7 = 0; i7 < 12; i7++) */
/* 	       if (tmp % pow7[i7]) */
/* 		    break; */
/* 	  tmp = tmp / pow7[i7-1]; */
/* 	  for(i5 = 0; i5 < 14; i5++) */
/* 	       if (tmp % pow5[i5]) */
/* 		    break; */
/* 	  tmp = tmp / pow5[i5-1]; */
/* 	  for(i3 = 0; i3 < 20; i3++) */
/* 	       if (tmp % pow3[i3]) */
/* 		    break; */
/* 	  tmp = tmp / pow3[i3-1]; */
/* 	  for(i2 = 0; i2 < 32; i2++) */
/* 	       if (tmp % pow2[i2]) */
/* 		    break; */
/* 	  if (tmp == pow2[i2-1]) */
/* 	       *humble_index++ = i; */
/*      } */
     
/*      while(scanf("%d", &i)){ */
/* 	  if (i == 0) break; */
/* 	  switch(i % 10){ */
/* 	  case 1: */
/* 	       printf("The %dst humble number is %d.\n", i, humble[i]); */
/* 	       break; */
/* 	  case 2: */
/* 	       printf("The %dnd humble number is %d.\n", i, humble[i]); */
/* 	       break; */
/* 	  case 3: */
/* 	       printf("The %drd humble number is %d.\n", i, humble[i]); */
/* 	       break; */
/* 	  default: */
/* 	       printf("The %dth humble number is %d.\n", i, humble[i]); */
/* 	       break; */
/* 	  } */
/*      } */

/*      return 0; */
/* } */

